package myLinkedList;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class LinkedListTest {
    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        //foreach遍历
        for(Integer x : list){
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("==========");
        //正序迭代器
        ListIterator<Integer> it1 = list.listIterator();
        while(it1.hasNext()){
            System.out.print(it1.next() + " ");
        }
        System.out.println();

        //倒序迭代器
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous() + " ");
        }
        System.out.println();
    }
}
